package com.aegis.gateway.config;

import cn.dev33.satoken.reactor.filter.SaReactorFilter;
import com.aegis.gateway.filter.SaFilterAuthStrategy;
import com.aegis.gateway.filter.SaFilterErrorStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author renogo
 *
 * @Version 1.0
 * @Descritube
 */
@Configuration
@Slf4j
@EnableConfigurationProperties(GatewayProperties.class)
public class SaTokenConfigure {


    // 注册 Sa-Token全局过滤器
    @Bean
    public SaReactorFilter getSaReactorFilter(SaFilterAuthStrategy saFilterAuthStrategy,
                                              SaFilterErrorStrategy saFilterErrorStrategy) {
        return new SaReactorFilter()
                // 拦截地址
                // /* 拦截全部path */
                .addInclude("/**")
                // 开放地址
                .addExclude("/favicon.ico")
                // 鉴权方法：每次访问进入
                .setAuth(saFilterAuthStrategy)
                .setError(saFilterErrorStrategy);
    }


}
